<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/11/9 0009
  Time: 14:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <script src="/resource/js/jquery-1.9.1.js" type="text/javascript"></script>
  <script src="/resource/js/layer/layer.js" type="text/javascript"></script>
  <title>会员充值</title>
  <style type="text/css">
    *{
      margin: 0;
      padding: 0;
      font-family: "本墨绪圆";
      font-size: 12px;
    }
    .alert-form-cnt{
      width: 60%;
      display: inline-block;
    }

    .alert-form-title{
      width: 20%;
      text-align: right;
      display: inline-block;
      margin-left: 5%;
    }
    .btn{
      margin-left: 38%;
      margin-top: 30px;
      background: #27B5F3;
      border: 0;
      color: #FFF;
      width: 120px;
      height: 34px;
      border-radius: 5px;
    }
    .form-control{
      display: inline;
      width: 100%;
      height: 24px;
      font-size: 14px;
      color: #555;
      background-color: #fff;
      background-image: none;
      border: 1px solid #ccc;
      padding-left: 5px;
    }
    .row{
      margin-top: 10px;
    }
    #jsForm{
      margin-top: 30px;
    }
    .searchBox{
      width: 68%;
      height: 80%;
      overflow: scroll;
      border: 1px solid #999;
      display: none;
      position: absolute;
      background: #FFF;
    }
    th{
      text-align: center;
      background: #ddd;
      padding: 2px 0;
      color: #666;
      width: 25%;
    }
    td{
      text-align: center;
      padding: 2px 0;
      border-bottom: 1px solid #CCC;
      width: 25%;
    }
    tr:last-child td{
      border-bottom: 0;
    }
    .down{
      background: #27B5F3;
      color: #FFF;
      padding: 3px 10px;
      display: inline-block;
      margin-left: 10px;
      border-radius: 5px;

      cursor: pointer;
    }
    .hid{

      display: block;
    }
  </style>
</head>
<body>

<form action="" method="post" id="jsForm">
  <div class="row clearfix">
    <div class="alert-form-title">客户查询：</div>
    <div class="alert-form-cnt"  style="width:47%;">
      <input type="text" class="form-control search" id="searchCondition" placeholder="请按姓名、手机或编号搜索">
      <table class="searchBox" cellspacing="0">
        <thead>
        <tr>
          <th>序号</th>
          <th>姓名</th>
          <th>手机号</th>
          <th>客户类型</th>
        </tr>
        </thead>
        <tbody id="memberData">
        <%--<tr >
          <td>1</td>
          <td>李四</td>
          <td>1676455664</td>
          <td>会员</td>
        </tr>--%>
        </tbody>
      </table>
    </div>
    <div class="down">搜索</div>
  </div>
  <div class="row clearfix">
    <div class="alert-form-title">姓&nbsp;&nbsp;名：</div>
    <div class="alert-form-cnt">
      <input type="text" style="cursor: not-allowed;color: #999999" class="form-control" id="memberName" disabled>
    </div>
  </div>
  <div class="row clearfix">
    <div class="alert-form-title">手机&nbsp;号：</div>
    <div class="alert-form-cnt">
      <input type="text" style="cursor: not-allowed;color: #999999" class="form-control" id="memberPhone" disabled>
    </div>
  </div>
  <div class="row clearfix">
    <div class="alert-form-title">客户类型：</div>
    <div class="alert-form-cnt">
      <input type="text" style="cursor: not-allowed;color: #999999" class="form-control" id="memberType" disabled>
    </div>
  </div>
  <div class="row clearfix">
    <div class="alert-form-title">当前余额：</div>
    <div class="alert-form-cnt">
      <input type="text" style="cursor: not-allowed;color: #999999" class="form-control" id="memberBalance" disabled>
    </div>
  </div>
  <div class="row clearfix">
    <div class="alert-form-title">充值金额：</div>
    <div class="alert-form-cnt">
      <input type="text" class="form-control" id="rechargeMoney">
    </div>
  </div>
  <div class="row clearfix">
    <div class="alert-form-title">赠送金额：</div>
    <div class="alert-form-cnt">
      <input type="text" class="form-control" id="presenterMoney">
    </div>
  </div>
  <div class="row clearfix">
    <div class="alert-form-title">提成人员：</div>
    <div class="alert-form-cnt">
      <select type="text" class="form-control" style="width:103%;" id="empId">
        <c:forEach items="${list_emp}" var="emp">
          <option value="${emp.id}">${emp.empName}</option>
        </c:forEach>
      </select>
    </div>
  </div>
  <div class="row clearfix">
    <div class="alert-form-title">备&nbsp;&nbsp;注：</div>
    <div class="alert-form-cnt">
      <input type="text" class="form-control" id="rechargeRemark">
    </div>
  </div>
  <input type="hidden" id="memberId">
  <input type="hidden" value="${on}" id="aboolean">
  <div style="display: none" id="sss"></div>
  <button type="button" class="btn" id="btn">充&nbsp; 值</button>
</form>
<script>

  $(".down").click(function(){
      $("#memberData").empty();
      $.ajax({
          type: "POST",
          url: "/index/selectMemberByCondition.shtml",
          data: "searchCondition="+$.trim($("#searchCondition").val()),
          success: function(data){
              $.each(data,function (i,n) {
                  $("#memberData").append("<tr >\n" +
                      "          <td>"+i+"</td>\n" +
                      "          <td>"+n.memberName+"</td>\n" +
                      "          <td>"+n.memberPhone+"</td>\n" +
                      "          <td>"+n.memberType+"</td>\n" +
                      "          <td style='display: none'>"+n.money+"</td>\n" +
                      "          <td style='display: none'>"+n.id+"</td>\n" +
                      "        </tr>")
              });
              $(".searchBox").addClass("hid");
              $("#memberData tr").mouseover(function () {
                  $(this).css({"background": "#69CAD4"});
              });
              $("#memberData tr").mouseleave(function () {
                  $(this).css({"background": ""});
              })
              $("#memberData tr").click(function () {
                  $("#memberName").val($(this).children().eq(1).text());
                  $("#memberPhone").val($(this).children().eq(2).text());
                  $("#memberType").val($(this).children().eq(3).text());
                  $("#memberBalance").val($(this).children().eq(4).text());
                  $("#memberId").val($(this).children().eq(5).text());
                  $(".searchBox").removeClass("hid");
              })
          }
      });
  })

  $("#btn").click(function () {
      var reg=/^[0-9]*[1-9][0-9]*$/;
      var reg1=/^[0-9]*[0-9][0-9]*$/;
      var memberId=$("#memberId").val();
      var rechargeMoney=$("#rechargeMoney").val();
      var presenterMoney=$("#presenterMoney").val();
      var rechargeRemark=$("#rechargeRemark").val();
      var empId=$("#empId").val();
      if(memberId==""){
          layer.msg("请选择会员!");
          return false;
      }else if(!reg.test($.trim(rechargeMoney))){
          $("#rechargeMoney").val(0);
          layer.msg("请输入适当充值金额(整数)!");
          return false;
      }else if(!reg1.test($.trim(presenterMoney))){
          $("#presenterMoney").val(0);
          layer.msg("请输入适当赠送金额(整数)!");
          return false;
      }else{
          $.ajax({
              url: "/memberInfo/accountRecharge.shtml",
              type: "POST",
              data: {"memberId":memberId,
                  "rechargeMoney":rechargeMoney,
                  "rechargeRemark":rechargeRemark,
                  "empId":empId},
              beforeSend: function () {
                  //改变提交按钮上的文字并将按钮设置为不可点击
                  $(this).val('提交中').attr('disabled', true);
              },
              success: function (data) {
                  var aboolean = $("#aboolean").val();
                  if (aboolean=="true") {//打印小票开关开启
                      $.ajax({
                          url: '/memberInfo/selectRechargeDetailInfo.shtml',
                          type: 'post',
                          dataTytpe: "html",
                          success: function (data) {
                              $("#sss").append(data);
                              layer.msg("充值成功，打印小票中...");
                              setTimeout( webpageClose,2000);
                          },
                          error: function () {
                              layer.msg("打印异常请联系管理员！");
                          }
                      });
                  } else {//打印小票开关关闭
                      layer.msg(data.message);
                      setTimeout( webpageClose,2000);
                  }
              },
              error:function () {
                  layer.msg("充值异常，请联系管理员!");
              }
          });

      }
  })

  function webpageClose(){
      /*var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
      parent.layer.close(index); //再执行关闭*/
  }

</script>
</body>
</html>

